import request from "@/utils/request";
import type { RoleResponseData, RoleData, MenuResponseData, RoleSetMenuData } from "./type";
enum API {
  ALLROLE_URL = "/admin/acl/role",
  ADDROLE_URL = "/admin/acl/role/save",
  UPDATEROLE_URL = "/admin/acl/role/update",
  DELROLE_URL = "/admin/acl/role/remove",
  ALLMENU_URL = "/admin/acl/role/permissions",
  SETMENU_URL = "/admin/acl/role/setPermissions"
}

// 获取角色列表信息
export const reqRoleList = (page: number, limit: number, searchName: string) =>
  request.get<any, RoleResponseData>((API.ALLROLE_URL + `?page=${page}&limit=${limit}&searchName=${searchName}`) as any);
// 新增/修改角色
export const reqAddRole = (data: RoleData) => {
  if (data.id) {
    // 更新角色信息
    return request.put<any, any>(API.UPDATEROLE_URL, data);
  } else {
    // 新增角色
    return request.post<any, any>(API.ADDROLE_URL, data);
  }
};
// 删除角色
export const reqDelUser = (id: number) => request.get<any, any>(API.DELROLE_URL + `?id=${id}`);
// 获取角色对应菜单
export const reqMenuList = (id: number) => request.get<any, MenuResponseData>(API.ALLMENU_URL + `?id=${id}`);
// 设置角色对应的菜单
export const reqSetRoleMunu = (data: RoleSetMenuData) => request.post<any, any>(API.SETMENU_URL, data);
